package edu.tgc.web.controller.code;

import java.util.List;
import java.util.Map;

import org.abyss.common.web.controller.easyui.EasyuiResultBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.tgc.entity.code.TbCodeJglx;
import edu.tgc.service.code.CodeService;

@Controller
@RequestMapping(value = "/code/jglx")
public class JglxController {
    @Autowired
    private CodeService service;

    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(Integer id) {
        try {
            this.service.deleteJglx(id);
            return EasyuiResultBuilder.buildAjaxResult("删除成功", true, true);
        } catch (Exception e) {
            return EasyuiResultBuilder.buildAjaxResult("删除失败");
        }
    }

    @RequestMapping(value = "/page")
    @ResponseBody
    public Object getPage(Pageable pageable) {
        Page<TbCodeJglx> page = this.service.findJglxPage(pageable);
        return EasyuiResultBuilder.buildDataGridResult(page);
    }

    @RequestMapping(value = "/create")
    public String gotoCreate() {
        return "code/jglx/create";
    }

    @RequestMapping(value = "/manage")
    public String manage() {
        return "code/jglx/manage";
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Object save(TbCodeJglx jglx) {
        try {
            this.service.saveJglx(jglx);
            return EasyuiResultBuilder.buildAjaxResult("数据保存成功", true, true);
        } catch (Exception e) {
            return EasyuiResultBuilder.buildAjaxResult("编号不能重复，数据保存失败", false, false);
        }
    }

    @RequestMapping(value = "/treebox")
    @ResponseBody
    public Object treebox() {
        List<Map<String, Object>> list = this.service.findAllJglxTree();
        return list;
    }

    @RequestMapping(value = "/update")
    public String update(Integer id, ModelMap map) {
        TbCodeJglx jglx = this.service.findJglxPage(id);
        map.put("model", jglx);
        return "code/jglx/create";
    }

}
